package cn.wbu.zyh.mapper;

import cn.wbu.zyh.annotation.AutoFill;
import cn.wbu.zyh.dto.EmployeePageQueryDTO;
import cn.wbu.zyh.entity.Employee;
import cn.wbu.zyh.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EmployeeMapper {
    @Select("SELECT u.*, r.* FROM employee u LEFT JOIN role r ON u.username = r.username WHERE u.username = #{username};")
    Employee getByUsername(String username);

    Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);

    Page<Employee> pageQueryHasTeam(EmployeePageQueryDTO employeePageQueryDTO);

    @AutoFill(OperationType.UPDATE)
    void update(Employee employee);

    void updateRole(Employee employee);

    @Insert("insert into employee(name, username, password, phone, sex, id_number, status, created_time, updated_time, created_user, updated_user) " +
            "VALUES "+
            "(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createdTime}, #{updatedTime}, #{createdUser}, #{updatedUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Employee employee);

    @Insert("insert into role(username, role) VALUES (#{username}, #{role})")
    void insertRole(@Param("username") String username, @Param("role") String role);

}
